package com.example.springAutoHello;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(AutoHelloProperties.class)
@ConditionalOnClass(AutoHelloService.class)
@ConditionalOnProperty(prefix = "hello", value = "enabled", matchIfMissing = true)
public class AutoHelloConfig {

	@Autowired
	private AutoHelloProperties autoHelloProperties;

	@Bean
	@ConditionalOnMissingBean(AutoHelloService.class)
	public AutoHelloService getAutoHelloService() {
		AutoHelloService autoHelloService = new AutoHelloService();
		autoHelloService.setMessage(autoHelloProperties.getMsg());
		return autoHelloService;
	}
}
